class Solution {
    public static int[] twoSum(int[] nums, int target) {
        int i = 0, j = nums.length - 1;
        int[] a = new int[2];
        while (i < j) {
            int s = nums[i] + nums[j];
            if (s < target) {
                i++;
            } else if (s > target) {
                j--;
            } else {
                return new int[]{nums[i], nums[j]};
            }
        }
        return new int[0];
    }

    public static void main(String[] args) {
        int[] a = twoSum(new int[]{2, 7, 11, 15}, 9);
        for (int i : a) {
            System.out.println(i);
        }

    }
}